# Fri Dec  2 16:36:20 CST 2022

# yum install net-snmp-utils
# pip3 install flask -i https://pypi.tuna.tsinghua.edu.cn/simple

'''
@url: http://10.173.26.3:8080/getSnmpIpv6Address
@url: http://10.173.26.3:8080/getSnmpIpv4Address

@shell
ipv6: snmpwalk -v1 -c allbest 10.173.28.1 .1.3.6.1.2.1.4.35.1.4
ipv4: snmpwalk -v1 -c allbest 10.173.28.1 .1.3.6.1.2.1.4.22.1.2
mask: snmpwalk -v 1 -c allbest 10.173.28.1 .1.3.6.1.2.1.4.20.1.3
'''

from SnmpServer import SnmpServer;
from flask import Flask;


config = {
    'version': 1,
    'communication': 'allbest',
    'address': '10.173.28.1',
    'ipv6_oid': '.1.3.6.1.2.1.4.35.1.4',
    'ipv4_oid': '.1.3.6.1.2.1.4.22.1.2',
    'mask_oid': '.1.3.6.1.2.1.4.20.1.3',
}
snmp_result = SnmpServer(config);
app = Flask(__name__);


@app.route('/')
def index():
    data = {
        'ipv6': 'http://10.173.26.3:8080/getSnmpIpv6Address',
        'ipv4': 'http://10.173.26.3:8080/getSnmpIpv4Address'
    }
    return snmp_result.result(data);


# ipv6
@app.route('/getSnmpIpv6Address')
def getSnmpIpv6Address():
    ipv6 = snmp_result.getSnmpIpv6Address();
    return ipv6;

# ipv4
@app.route('/getSnmpIpv4Address')
def getSnmpIpv4Address():
    address_division = snmp_result.addressDivision();
    return address_division;

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=False, processes=False );
